package com.sunny.blog.service.impl;

import com.sunny.blog.mapper.SysLogMapper;
import com.sunny.blog.pojo.SysLog;
import com.sunny.blog.service.ISysLogService;
import com.sunny.blog.util.CommonUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 系统日志表 服务实现类
 * </p>
 *
 * @author sunt
 * @since 2020-05-22
 */
@Service
public class SysLogServiceImpl implements ISysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    @Transactional
    public void insertSysLog(SysLog sysLog) {
        sysLog.setLogId(Long.valueOf(CommonUtil.genId()));
        sysLogMapper.insert(sysLog);
    }

    @Override
    public void sendDelayMsgToMQ(String exchange, String routeKey, String data,int delayTime) {
        rabbitTemplate.convertAndSend(exchange, routeKey, data, message -> {
            message.getMessageProperties().setExpiration(delayTime + "");
            return message;
        });
    }
}
